
// Definition for a binary tree node.
function TreeNode(val) {
    this.val = val;
    this.left = this.right = null;
}

/**
 * @param {TreeNode} root
 * @return {number}
 */
var numColor = function(root) {
  let set = new Set();
  function preView(node) {
    if(!node) return;
    if(!set.has(node.val)) {
      set.add(node.val);
    }
    preView(node.left);
    preView(node.right);
  }
  preView(root);
  return [...set].length;
};
